package main

import (
	"fmt"
	"sync"
	"time"
)

func main()  {
	m := make(map[string]int)
	m["a"] = 1
	m["b"] = 2
	fmt.Println(m)

	//user
	n := map[int]user{
		1:{"tim",18},
	}
	u := n[1]
	u.age += 13
	n[1] = u //设置整个value
	fmt.Println(n)

	//指针类型
	p := map[int]*user{
		1:&user{"haha",23},
	}
	p[1].age += 22
	fmt.Println(p[1].age)

	//nil和空不一样
	var m1 map[int]string
	m2 := map[int]string{}
	fmt.Println(m1 == nil,m2 == nil)

	mapsTest1()
}

type user struct {
	name string
	age int
}

func mapsTest1()  {
	var lock sync.RWMutex
	m3 := make(map[string]int)
	go func() {
		for{
			lock.Lock()
			m3["m3a"] += 1
			lock.Unlock()
			time.Sleep(time.Second)
		}
	}()
	go func() {
		for{
			lock.RLock()
			fmt.Println(m3["m3a"])
			lock.RUnlock()
			time.Sleep(time.Second)
		}
	}()

	select {
	}
}
